// Generated file

// clang-format off
const char *g_block_modifier_shader_template_0 =
"#version 450\n"
"\n"
"layout (local_size_x = 4, local_size_y = 4, local_size_z = 4) in;\n"
"\n"
"layout (set = 0, binding = 0, std430) restrict readonly buffer Params {\n"
"	vec3 origin_in_voxels;\n"
"	float voxel_size;\n"
"	ivec3 block_size;\n"
"	int buffer_offset;\n"
"} u_params;\n"
"\n"
"// SDF is modified in-place\n"
"layout (set = 0, binding = 1, std430) restrict buffer InSDBuffer {\n"
"	float values[];\n"
"} u_inout_sd;\n"
"\n"
"// Parameters common to all modifiers.\n"
"// Keeping the same binding number as other shader types, to simplify usage in C++\n"
"layout (set = 0, binding = 4, std430) restrict readonly buffer BaseModifierParams {\n"
"	mat4 world_to_model;\n"
"	int operation;\n"
"	float smoothness;\n"
"	float sd_scale;\n"
"} u_base_modifier_params;\n"
"\n";
// clang-format on

// clang-format off
const char *g_block_modifier_shader_template_1 =
"\n"
"float sd_smooth_union(float a, float b, float s) {\n"
"	const float h = clamp(0.5 + 0.5 * (b - a) / s, 0.0, 1.0);\n"
"	return mix(b, a, h) - s * h * (1.0 - h);\n"
"}\n"
"\n"
"// Inverted a and b because it subtracts SDF a from SDF b\n"
"float sd_smooth_subtract(float b, float a, float s) {\n"
"	const float h = clamp(0.5 - 0.5 * (b + a) / s, 0.0, 1.0);\n"
"	return mix(b, -a, h) + s * h * (1.0 - h);\n"
"}\n"
"\n"
"int get_zxy_index(ivec3 pos, ivec3 size) {\n"
"	return pos.y + size.y * (pos.x + size.x * pos.z);\n"
"}\n"
"\n"
"void main() {\n"
"	const ivec3 rpos = ivec3(gl_GlobalInvocationID.xyz);\n"
"\n"
"	// The output buffer might not have a 3D size multiple of our group size.\n"
"	// Some of the parallel executions will not do anything.\n"
"	if (rpos.x >= u_params.block_size.x || rpos.y >= u_params.block_size.y || rpos.z >= u_params.block_size.z) {\n"
"		return;\n"
"	}\n"
"\n"
"	vec3 pos = u_params.origin_in_voxels + vec3(rpos) * u_params.voxel_size;\n"
"\n"
"	pos = (u_base_modifier_params.world_to_model * vec4(pos, 1.0)).xyz;\n"
"\n"
"	const int index = get_zxy_index(rpos, u_params.block_size) + u_params.buffer_offset;\n"
"\n"
"	float sd = u_inout_sd.values[index];\n"
"\n"
"	const float msd = get_sd(pos) * u_base_modifier_params.sd_scale;\n"
"\n"
"	if (u_base_modifier_params.operation == 0) {\n"
"		sd = sd_smooth_union(sd, msd, u_base_modifier_params.smoothness);\n"
"\n"
"	} else if (u_base_modifier_params.operation == 1) {\n"
"		sd = sd_smooth_subtract(sd, msd, u_base_modifier_params.smoothness);\n"
"\n"
"	} else {\n"
"		sd = msd;\n"
"	}\n"
"\n"
"	u_inout_sd.values[index] = sd;\n"
"}\n";
// clang-format on
